﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using System.Data.SqlClient;
using System.Data;
using BestLifePOS_Core.Exceptions.DataBase;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeCalculationItemDetailsDataAction:BestLifeDataAction<List<Price_List>>
    {
         private decimal GvCost;
         private decimal GvRetprice;

        public BestLifeCalculationItemDetailsDataAction(decimal PCost,decimal PRetprice)
        {
            GvCost = PCost;
            GvRetprice = PRetprice;
        }

        public override List<Price_List> Body(SqlConnection PConn)
        {
            try
            {
                List<Price_List> LvList = new List<Price_List>();


                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.ItemDetailsCalculation";
                LvCommand.Parameters.Add(new SqlParameter("@Ret_Price", GvRetprice));
                LvCommand.Parameters.Add(new SqlParameter("@Pur_price ", GvCost));

                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                        Price_List LvPricelist = new Price_List();
                        LvPricelist.PV=Convert.ToDecimal(LvReader.GetValue(1).ToString());
                        LvPricelist.BV=Convert.ToDecimal(LvReader.GetValue(0).ToString());
                        LvPricelist.Pro_Price = Convert.ToDecimal(LvReader.GetValue(2).ToString());


                        LvList.Add(LvPricelist);
                }
                return LvList;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
